% emacs: -*- mode: latex; coding: utf-8; -*- 

% Copyright (c) 2007, ChenZaichun
% LISENCE: creative common version 3
%

\documentclass[a4paper,11pt]{article}

% for chinese input
\usepackage{CJKutf8}
\usepackage[utf8]{inputenc}   % replace by the encoding you are using
\usepackage[T1]{fontenc}
\usepackage{fancybox}
% author and title
\author{ChenZaichun}
%\title{}

% for listing code
\usepackage{listings}
\usepackage{xcolor}

% for layout
\usepackage[margin=1in]{geometry}
%\usepackage{layouts}

% header and footnode
\usepackage{fancyhdr}

%\usepackage[sf]{titlesec}
%\usepackage{titletoc}
\usepackage{makeidx,shortvrb,latexsym}

%\newcommand{\tsimr}[1]{\multirow{2}*{#1}}

\begin{CJK}{UTF8}{simhei}
\gdef\cname{目 录}
\end{CJK}

\renewcommand\contentsname{\cname}

\makeatletter
\renewcommand\tableofcontents{%
    \section*{{\centering\rule{\textwidth}{0.5pt}\\[1ex]\huge{\contentsname}\\[0.8ex]\rule{\textwidth}{0.5pt}}
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%

    }
\makeatother

% ifthen package
\usepackage{ifthen}
\newif\ifpdf
\ifx\pdfoutput\undefined
  \pdffalse
\else
  \pdftrue
\fi

\ifpdf
  \usepackage[colorlinks,linkcolor=blue,
		hyperindex,
                pdfstartview=FitH,
                plainpages=false,
                bookmarksnumbered=true,
                unicode,
                pdftex]
                {hyperref}
  \usepackage[pdftex]{graphicx}
  \pdfoutput=1
  \pdfmapfile{=simhei.map}
\else
  \usepackage{graphicx}
  \usepackage{hyperref}
\fi

% tex2page
\usepackage{tex2page} 

\usepackage{CJKnumb, indentfirst}

\renewcommand{\arraystretch}{1.2}

% 修改行距，段间距和字间距
\linespread{1.2}
\parskip=1.618ex
\renewcommand\CJKglue{\hskip -0.3pt plus 0.08\baselineskip}

% for tables
\usepackage{tabularx}
\usepackage{booktabs,longtable}

% for listings
\texonly
\lstset{language=C++,%
  tabsize=4,%
  keepspaces=true,%
  breakindent=22pt,% 
  numbers=left,%
  stepnumber=1,%
  numberstyle=\tiny,%
  basicstyle=\footnotesize,%
  showspaces=false,%
  frame=shadowbox,%
  rulesepcolor=\color{red!20!green!20!blue!20},%
  keywordstyle=\color{blue!70},%
  commentstyle=\color{red!50!green!50!blue!50},%
  flexiblecolumns=true,%
  breaklines=true,%
  breakautoindent=true,%
  breakindent=4em,%
  escapeinside={(*@}{@*)},%
  xleftmargin=2em,%
  xrightmargin=2em,% 
  aboveskip=1em,%
  frameround=tftt,%
  nolol=true,%
  showstringspaces=false,%
  escapebegin=\begin{CJK*}{UTF8}{simhei},%
    escapeend=\end{CJK*},%
  texcl=true% 这句很重要，可将注释环境修改成中文环境！
} 
\endtexonly


